package com.jekun.helloworld.designmode.adapter.demo2;

/**
 * @author Administrator
 *
 * 创建适配器类
 */
public class MediaAdapter implements MediaPlayer {

    AdvancedMediaPlayer advancedMusicPlayer;

    public MediaAdapter(String audioType) {
        if (audioType.equalsIgnoreCase("vlc")) {
            advancedMusicPlayer = new VlcPlayer();
        } else if (audioType.equalsIgnoreCase("mp4")) {
            advancedMusicPlayer = new Mp4Player();
        }
    }

    @Override
    public String play(String audioType, String fileName) {
        switch (audioType) {
            case ConstantAudioPlayer.VLC:
                return advancedMusicPlayer.playVlc(fileName);
            case ConstantAudioPlayer.MP3:
                return advancedMusicPlayer.playMp4(fileName);
            default:
                return "Invalid media";
        }
    }
}